package ken.spring.cloud.alibaba;
import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import com.alibaba.csp.sentinel.datasource.Converter;
import ken.spring.cloud.alibaba.exception.ExceptionUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;


/**
 * <ul>
 * <li>Title: RibbonConfig</li>
 * <li>Description: 异步回调成功 </li>
 * </ul>
 *
 * @author
 * @date 2022/7/2 12:50
 */
@Configuration
public class RibbonConfig {

    @Bean
    //@LoadBalanced
    @SentinelRestTemplate(blockHandler = "handleBlock",
            blockHandlerClass = ExceptionUtil.class,fallback = "fallBack",fallbackClass = ExceptionUtil.class)
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    //限流规则
    @Bean
    public Converter myConverter() {
        return new JsonFlowRuleListConverter();
    }


    //默认的断路器配置
  /*  @Bean
    public Customizer<SentinelCircuitBreakerFactory> defaultConfig() {
        return factory -> {
            factory.configureDefault(
                    id -> new SentinelConfigBuilder().resourceName(id)
                            .rules(Collections.singletonList(new DegradeRule(id)
                                    .setGrade(RuleConstant.DEGRADE_GRADE_RT).setCount(100)
                                    .setTimeWindow(10)))
                            .build());
        };
    }*/
}
